import Vue from 'vue'
import Router from 'vue-router'
import iView from 'iview'
import Cookies from 'js-cookie'
// import HelloWorld from '@/components/HelloWorld'

import { routes } from './router';
Vue.use(Router)

const router = new Router({
  routes
})


router.beforeEach((to, from, next) => {
  iView.LoadingBar.start();
  if (to.name !== "login" && !Cookies.get("userMessage")) {
    next({
      name: "login"
    })
  } else if (to.name === "login" && Cookies.get("userMessage")) {
    next({
      path:"/home"
    })
  } else {
    next()
  }

})

router.afterEach((to, from) => {
  iView.LoadingBar.finish();
})
export default router
// export default new Router({
//   routes: [
//     {
//       path: '/',
//       name: 'HelloWorld',
//       component: HelloWorld
//     }
//   ]
// })
